/* icintr1a.p - GENERATE ADDITIONAL GL TRANSACTIONS FOR BACK EXPLODE RECEIPTS*/
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: icintr1a.p 81608 2017-11-20 05:35:14Z ipa                         $: */
/* REVISION: 6.0      LAST MODIFIED: 06/22/90   BY: emb *D033*               */
/* REVISION: 6.0      LAST MODIFIED: 10/12/90   BY: emb *D098*               */
/* REVISION: 6.0      LAST MODIFIED: 03/13/91   BY: WUG *D472*               */
/* REVISION: 7.0      LAST MODIFIED: 09/18/91   BY: pma *F003*               */
/* REVISION: 7.0      LAST MODIFIED: 07/09/92   BY: pma *F748*               */
/* REVISION: 7.0      LAST MODIFIED: 07/31/92   BY: pma *F821*               */
/*           7.3                     10/29/94   BY: bcm *GN73*               */
/*           7.3                     01/16/96   BY: ame *G1K4*               */
/* REVISION: 8.5      LAST MODIFIED: 07/31/95   BY: taf *J053*               */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 8.6E     LAST MODIFIED: 07/15/98   BY: *L024* Bill Reckard      */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Robin McCarthy    */
/* REVISION: 9.1      LAST MODIFIED: 04/25/00   BY: *N0CF* Santosh Rao       */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* myb               */
/* Revision: 1.17     BY: Niranjan R.        DATE: 07/12/01 ECO: *P00L*      */
/* Revision: 1.19     BY: Paul Donnelly (SB) DATE: 06/26/03 ECO: *Q00G*      */
/* Revision: 1.20     BY: Veena Lad          DATE: 03/26/04 ECO: *P1VV*      */
/* Revision: 1.21     BY: Inna Fox           DATE: 06/21/04 ECO: *P1CZ*      */
/* Revision: 1.22     BY: Prabu M       DATE: 06/09/09 ECO: *Q2ZN*   */
/* $Revision: 1.25 $    BY: Huaping Luo       DATE: 06/09/09 ECO: *R21W*   */
/*-Revision end---------------------------------------------------------------*/
 
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
 
{us/bbi/mfdeclre.i}
 
{us/px/pxmaint.i}
{us/px/pxphdef.i ictrxr}
 
define input parameter ipCreateLabor as logical no-undo.
 
define shared variable pt_recid as recid.
define shared variable eff_date like glt_effdate label "Effective".
define shared variable nbr like tr_nbr.
define shared variable cr_acct like trgl_cr_acct.
define shared variable cr_sub like trgl_cr_sub.
define shared variable cr_cc like trgl_cr_cc.
define shared variable qty_iss_rcv like tr_qty_loc.
define shared variable accum_wip like trgl_gl_amt.
define shared variable cr_proj like trgl_cr_proj.
define shared variable lotserial_qty like sr_qty no-undo.
 
define variable gl_amt like trgl_gl_amt.
define variable ref like glt_ref.
define variable assy_wip_proj like trgl_cr_proj.
define variable assy_wip_acct like pl_wip_acct.
define variable assy_wip_sub like pl_wip_sub.
define variable assy_wip_cc like pl_wip_cc.
define variable l_isUnpBackExplode as logical no-undo.
define shared variable wip_entity like si_entity.
define shared variable sct_recid as recid.
define shared variable tr_recno as recid.
 
/* trgl_det account variables */
{us/ic/icglacct.i}
 
define variable mc-error-number like msg_nbr no-undo.
         define variable dftOVHAcct       like pl_ovh_acct no-undo.
         define variable dftOVHSubAcct    like pl_ovh_sub  no-undo.
         define variable dftOVHCostCenter like pl_ovh_cc   no-undo.
         define variable dftWVARAcct       like pl_flr_acct no-undo.
         define variable dftWVARSubAcct    like pl_flr_sub  no-undo.
         define variable dftWVARCostCenter like pl_flr_cc   no-undo.
         define variable dftCOPAcct       like pl_cop_acct no-undo.
         define variable dftCOPSubAcct    like pl_cop_sub  no-undo.
         define variable dftCOPCostCenter like pl_cop_cc   no-undo.
 
for first gl_ctrl
       where gl_ctrl.gl_domain = global_domain no-lock:
end. /* FOR FIRST GL_CTRL */
 
for first pt_mstr
      where recid(pt_mstr) = pt_recid no-lock:
end. /* FOR FIRST PT_MSTR */
 
find first icc_ctrl no-lock where
   icc_domain = global_domain no-error.
 
for first pl_mstr
       where pl_mstr.pl_domain = global_domain and  pl_prod_line = pt_prod_line
       no-lock:
end. /* FOR FIRST PL_MSTR */
 
for first sct_det
      where recid(sct_det) = sct_recid no-lock:
end. /* FOR FIRST SCT_DET */
 
for first tr_hist
      where recid(tr_hist) = tr_recno no-lock:
end. /* FOR FIRST TR_HIST */
 
assign
   assy_wip_acct = cr_acct
   assy_wip_sub  = cr_sub
   assy_wip_cc   = cr_cc
   assy_wip_proj = cr_proj.
 
if ipCreateLabor and sct_lbr_tl <> 0 then do:
   gl_amt = sct_lbr_tl * qty_iss_rcv.
 
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output gl_amt,
                 input gl_rnd_mthd,
                 output mc-error-number)" }
   if mc-error-number <> 0 then do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
   end.
 
   accum_wip = accum_wip + gl_amt.
 
   if available tr_hist then do:
 
      {us/px/pxrun.i &PROC  = 'createTrglDetRecord'
           &PROGRAM='ictrxr.p'
           &handle = ph_ictrxr
           &PARAM = "(input tr_trnbr,
                      input ""RCT-LBR"",
                      input assy_wip_acct,
                      input assy_wip_sub,
                      input assy_wip_cc,
                      input assy_wip_proj,
                      input gl_lbr_acct,
                      input gl_lbr_sub,
                      input gl_lbr_cc,
                      input assy_wip_proj,
                      input gl_amt,
 
                      input yes, /* create glt_det */
                      input ""RCT-WO"",
                      input nbr, /* order # */
                      input wip_entity, /* entity */
                      input eff_date,   /* effective date */
                      input icc_gl_sum, /* summarize */
                      input icc_mirror, /* audit */
                      input recid(tr_hist),
                      input """", /* inter company ref# */
                      input """", /* currency */
                      input 0,    /* exchange rate */
                      input 0,    /* exchange rate 2 */
                      input """", /* exchange rate type */
                      input 0,    /* currency amount */
                      input-output ref, /* glt_ref */
 
                      output oidTrglDet
                     )"
          &NOAPPERROR=true
          &CATCHERROR=true}
 
   end. /* if available tr_hist */
 
 
 
end.
 
if ipCreateLabor and sct_bdn_tl <> 0 then do:
   gl_amt = sct_bdn_tl * qty_iss_rcv.
 
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output gl_amt,
                 input gl_rnd_mthd,
                 output mc-error-number)" }
   if mc-error-number <> 0 then do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
   end.
 
   accum_wip = accum_wip + gl_amt.
 
   if available tr_hist then do:
 
             {us/px/pxrun.i &PROC  = 'createTrglDetRecord'
                &PROGRAM='ictrxr.p'
                &handle = ph_ictrxr
                &PARAM = "(input tr_trnbr,
                           input ""RCT-BDN"",
                           input assy_wip_acct,
                           input assy_wip_sub,
                           input assy_wip_cc,
                           input assy_wip_proj,
                           input gl_bdn_acct,
                           input gl_bdn_sub,
                           input gl_bdn_cc,
                           input assy_wip_proj,
                           input gl_amt,
 
                           input yes, /* create glt_det */
                           input ""RCT-WO"",
                           input nbr, /* order # */
                           input wip_entity, /* entity */
                           input eff_date,   /* effective date */
                           input icc_gl_sum, /* summarize */
                           input icc_mirror, /* audit */
                           input recid(tr_hist),
                           input """", /* inter company ref# */
                           input """", /* currency */
                           input 0,    /* exchange rate */
                           input 0,    /* exchange rate 2 */
                           input """", /* exchange rate type */
                           input 0,    /* currency amount */
                           input-output ref, /* glt_ref */
 
                           output oidTrglDet
                          )"
                &NOAPPERROR=true
                &CATCHERROR=true}
 
   end. /* if available tr_hist then do: */
 
end.
 
if sct_ovh_tl <> 0 then do:
   gl_amt = sct_ovh_tl * qty_iss_rcv.
 
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output gl_amt,
                 input gl_rnd_mthd,
                 output mc-error-number)" }
   if mc-error-number <> 0 then do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
   end.
 
   accum_wip = accum_wip + gl_amt.
 
   if available tr_hist then do:
         /* Determine if default GL account exists */
         /* see if address is a vendor.. if so, use it */
      for first vd_mstr
          where vd_mstr.vd_domain = global_domain and  vd_addr = tr_addr
         no-lock:
      end.
 
      {us/bbi/gprun.i ""glactdft.p"" "(input ""PO_OVH_ACCT"",
                                input pt_prod_line,
                                input tr_site,
                                input if available vd_mstr then
                                      vd_type else """",
                                input """",
                                input no,
                                output dftOVHAcct,
                                output dftOVHSubAcct,
                                output dftOVHCostCenter)"}
 
          {us/px/pxrun.i &PROC  = 'createTrglDetRecord'
              &PROGRAM='ictrxr.p'
              &handle = ph_ictrxr
              &PARAM = "(input tr_trnbr,
                         input ""RCT-OVH"",
                         input assy_wip_acct,
                         input assy_wip_sub,
                         input assy_wip_cc,
                         input assy_wip_proj,
                         input dftOVHAcct,
                         input dftOVHSubAcct,
                         input dftOVHCostCenter,
                         input assy_wip_proj,
                         input gl_amt,
 
                         input yes, /* create glt_det */
                         input ""RCT-WO"",
                         input nbr, /* order # */
                         input wip_entity, /* entity */
                         input eff_date,   /* effective date */
                         input icc_gl_sum, /* summarize */
                         input icc_mirror, /* audit */
                         input recid(tr_hist),
                         input """", /* inter company ref# */
                         input """", /* currency */
                         input 0,    /* exchange rate */
                         input 0,    /* exchange rate 2 */
                         input """", /* exchange rate type */
                         input 0,    /* currency amount */
                         input-output ref, /* glt_ref */
 
                         output oidTrglDet
                        )"
              &NOAPPERROR=true
              &CATCHERROR=true}
 
   end. /* if available tr_hist then do */
 
          /* Replaced pl_ovh_acct, pl_ovh_sub AND pl_ovh_cc with */
          /* dftOVHAcct, dftOVHSubAcct and dftOVHCostCenter      */
 
end.
 
if ipCreateLabor and sct_sub_tl <> 0 then do:
   gl_amt = sct_sub_tl * qty_iss_rcv.
 
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output gl_amt,
                 input gl_rnd_mthd,
                 output mc-error-number)" }
   if mc-error-number <> 0 then do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
   end.
 
   accum_wip = accum_wip + gl_amt.
 
   if available tr_hist then do:
      /* Determine if default gl account exists */
      {us/bbi/gprun.i ""glactdft.p"" "(input ""WO_COP_ACCT"",
                                input pt_prod_line,
                                input tr_site,
                                input """",
                                input """",
                                input no,
                                output dftCOPAcct,
                                output dftCOPSubAcct,
                                output dftCOPCostCenter)"}
 
          {us/px/pxrun.i &PROC  = 'createTrglDetRecord'
              &PROGRAM='ictrxr.p'
              &handle = ph_ictrxr
              &PARAM = "(input tr_trnbr,
                         input ""RCT-SUB"",
                         input assy_wip_acct,
                         input assy_wip_sub,
                         input assy_wip_cc,
                         input assy_wip_proj,
                         input dftCOPAcct,
                         input dftCOPSubAcct,
                         input dftCOPCostCenter,
                         input assy_wip_proj,
                         input gl_amt,
 
                         input yes, /* create glt_det */
                         input ""RCT-WO"",
                         input nbr, /* order # */
                         input wip_entity, /* entity */
                         input eff_date,   /* effective date */
                         input icc_gl_sum, /* summarize */
                         input icc_mirror, /* audit */
                         input recid(tr_hist),
                         input """", /* inter company ref# */
                         input """", /* currency */
                         input 0,    /* exchange rate */
                         input 0,    /* exchange rate 2 */
                         input """", /* exchange rate type */
                         input 0,    /* currency amount */
                         input-output ref, /* glt_ref */
 
                         output oidTrglDet
                        )"
              &NOAPPERROR=true
              &CATCHERROR=true}
 
   end. /* if available tr_hist then do: */
 
         /* Replaced pl_cop_acct, pl_cop_sub AND pl_cop_cc with */
         /* dftCOPAcct, dftCOPSubAcct and dftCOPCostCenter      */
 
end.
 
if accum_wip <> 0 then do:
   gl_amt = - accum_wip.
 
   {us/gp/gprunp.i "mcpl" "p" "mc-curr-rnd"
      "(input-output gl_amt,
                 input gl_rnd_mthd,
                 output mc-error-number)" }
   if mc-error-number <> 0 then do:
      {us/bbi/pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
   end.
 
   if available tr_hist 
   then do:
      /* Determine if default gl account exists */
      {us/bbi/gprun.i ""glactdft.p"" "(input ""WO_WVAR_ACCT"",
                                input pt_prod_line,
                                input tr_site,
                                input """",
                                input """",
                                input no,
                                output dftWVARAcct,
                                output dftWVARSubAcct,
                                output dftWVARCostCenter)"}
 
      {us/px/pxrun.i &PROC  = 'createTrglDetRecord'
          &PROGRAM='ictrxr.p'
          &handle = ph_ictrxr
          &PARAM = "(input tr_trnbr,
                     input ""RCT-WOVAR"",
                     input assy_wip_acct,
                     input assy_wip_sub,
                     input assy_wip_cc,
                     input assy_wip_proj,
                     input dftWVARAcct,
                     input dftWVARSubAcct,
                     input dftWVARCostCenter,
                     input assy_wip_proj,
                     input gl_amt,
 
                     input yes, /* create glt_det */
                     input ""WIP-ADJ"",
                     input nbr, /* order # */
                     input wip_entity, /* entity */
                     input eff_date,   /* effective date */
                     input icc_gl_sum, /* summarize */
                     input icc_mirror, /* audit */
                     input recid(tr_hist),
                     input """", /* inter company ref# */
                     input """", /* currency */
                     input 0,    /* exchange rate */
                     input 0,    /* exchange rate 2 */
                     input """", /* exchange rate type */
                     input 0,    /* currency amount */
                     input-output ref, /* glt_ref */
 
                     output oidTrglDet
                    )"
          &NOAPPERROR=true
          &CATCHERROR=true}
   end. /*  if available tr_hist then do: */

   /* THE SUBSCRIBE FOR THE STATEMENT BELOW IS AVAILABLE ONLY VIA icunrc01.p */
   l_isUnpBackExplode = false.
   publish "isUnpBackExplode" (output l_isUnpBackExplode).
   
   if not available tr_hist
      and lotserial_qty = 0 
      and l_isUnpBackExplode
   then do:
       assign
          dftwvaracct       = pl_wvar_acct
          dftwvarsubacct    = pl_wvar_sub
          dftwvarcostcenter = pl_wvar_cc.

       {us/px/pxrun.i &PROC='createGltDetRecord'
           &PROGRAM='ictrxr.p'
           &handle = ph_ictrxr
           &PARAM =  "(input gl_amt,            /* pAmount */
                       input ""WIP-ADJ"",       /* pTranstype */
                       input nbr,               /* pNbr */
                       input assy_wip_acct,     /* pDebitAcct */
                       input assy_wip_sub,      /* pDebitSub */
                       input assy_wip_cc,       /* pDebitCC */
                       input assy_wip_proj,     /* pDebitProj */
                       input dftWVARAcct,       /* pCreditAcct */
                       input dftWVARSubAcct,    /* pCreditSub */
                       input dftWVARCostCenter, /* pCreditCC */
                       input assy_wip_proj,     /* pCreditProj */
                       input wip_entity,        /* pEntity */
                       input eff_date,          /* pEffectDate */
                       input icc_gl_sum,        /* pSummarize */
                       input icc_mirror,        /* pAudit */
                       input ?,                 /* pTrglRecno */
                       input ?,                 /* pTrRecno */
                       input """",              /* pInterCompRef */
                       input """",              /* pManageCurrency */
                       input 0,                 /* pManageExRate */
                       input 0,                 /* pManageExRate2 */
                       input """",              /* pManageRateType */
                       input 0,                 /* pManageCurrencyAmt */
                       input-output ref)"       /* pRef */
           &NOAPPERROR=true
           &CATCHERROR=true}

   end. /* IF NOT AVAIALBLE tr_hist AND lotserial_qty = 0 .. */
   
end.  /* if accum_wip <> 0 */

